-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sys/net/nanocoap: fix buffer overflow in separate response handling #21075
Merged
maribu
merged 5 commits into
RIOT-OS:master
from
maribu:sys/net/nanocoap/buffer-overflow-separate-response
Dec 13, 2024
Merged
sys/net/nanocoap: fix buffer overflow in separate response handling #21075
maribu
merged 5 commits into
RIOT-OS:master
from
maribu:sys/net/nanocoap/buffer-overflow-separate-response
Dec 13, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
maribu
requested review from
leandrolanzieri,
aabadie,
MichelRottleuthner,
miri64 and
PeterKietzmann
as code owners
December 11, 2024 17:40
maribu
added
CI: ready for build
If set, CI server will compile all applications for all available boards for the labeled PR
Type: bug
The issue reports a bug / The PR fixes a bug (including spelling errors)
labels
Dec 11, 2024
github-actions
bot
added
Area: network
Area: Networking
Area: tests
Area: tests and testing framework
Area: CoAP
Area: Constrained Application Protocol implementations
Area: sys
Area: System
Area: examples
Area: Example Applications
labels
Dec 11, 2024
benpicco
reviewed
Dec 11, 2024
maribu
force-pushed
the
sys/net/nanocoap/buffer-overflow-separate-response
branch
from
December 11, 2024 19:20
41d8af4
to
6221061
Compare
maribu
force-pushed
the
sys/net/nanocoap/buffer-overflow-separate-response
branch
from
December 11, 2024 19:50
6221061
to
7e0c535
Compare
maribu
commented
Dec 11, 2024
maribu
force-pushed
the
sys/net/nanocoap/buffer-overflow-separate-response
branch
from
December 11, 2024 19:55
7e0c535
to
4c46407
Compare
maribu
added
the
Process: needs backport
Integration Process: The PR is required to be backported to a release or feature branch
label
Dec 11, 2024
maribu
force-pushed
the
sys/net/nanocoap/buffer-overflow-separate-response
branch
from
December 11, 2024 20:43
4c46407
to
c391765
Compare
benpicco
approved these changes
Dec 12, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even makes then code nicer :)
github-merge-queue
bot
removed this pull request from the merge queue due to failed status checks
Dec 12, 2024
C++ does not know about `restrict`, but both g++ and clang++ support `__restrict`, as do `clang` and GCC [1]. Using `__restrict` instead of `restrict` is also what glibc does. [1]: https://en.wikipedia.org/wiki/Restrict#Support_by_C++_compilers
When RFC 8974 support (module `nanocoap_token_ext`) is in use, the request token may be longer than the buffer in the separate response context is large. This adds a check to not overflow the buffer. Sadly, this is an API change: Preparing the separate response context can actually fail, so we need to report this with a return value. The example application has been adapted to only proceed if the separate reply context could have been prepared, and rather directly emit a reset message if the token exceeds the static buffer. Co-authored-by: benpicco <[email protected]>
This adds a function to convert a hex string to a byte array.
This adds the client_token shell command that allows to specify the CoAP Token. This is particularly useful to test extended length Tokens, as enabled with module `nanocoap_token_ext`. Co-authored-by: benpicco <[email protected]>
An RST message has no token, so don't reply with a token when sending RST. This also adds unit tests to ensure this this exact bug does not sneak back in.
maribu
force-pushed
the
sys/net/nanocoap/buffer-overflow-separate-response
branch
from
December 12, 2024 13:28
c391765
to
c7af4b2
Compare
github-actions
bot
added
Platform: AVR
Platform: This PR/issue effects AVR-based platforms
Area: cpu
Area: CPU/MCU ports
labels
Dec 12, 2024
nandojve
approved these changes
Dec 12, 2024
github-merge-queue
bot
removed this pull request from the merge queue due to failed status checks
Dec 12, 2024
Thx a lot! |
maribu
deleted the
sys/net/nanocoap/buffer-overflow-separate-response
branch
December 13, 2024 07:21
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Area: CoAP
Area: Constrained Application Protocol implementations
Area: cpu
Area: CPU/MCU ports
Area: examples
Area: Example Applications
Area: network
Area: Networking
Area: sys
Area: System
Area: tests
Area: tests and testing framework
CI: ready for build
If set, CI server will compile all applications for all available boards for the labeled PR
Platform: AVR
Platform: This PR/issue effects AVR-based platforms
Process: needs backport
Integration Process: The PR is required to be backported to a release or feature branch
Type: bug
The issue reports a bug / The PR fixes a bug (including spelling errors)
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Contribution description
When RFC 8974 support (module
nanocoap_token_ext
) is in use, the request token may be longer than the buffer in the separate response context is large. This adds a check to not overflow the buffer.Sadly, this is an API change: Preparing the separate response context can actually fail, so we need to report this with a return value.
The example application has been adapted to only proceed if the separate reply context could have been prepared, and rather directly emit a reset message if the token exceeds the static buffer.
Testing procedure
A second commit has been sneaked in to add the
client_token
shell command totests/net/nanocoap_cli
that allow specifying the Token as hex. The most recently set token is used inclient
.Preparation
Running the Server
This should be done with
master
and this PRcopy the
<IPV6_ADDR>
part of the outputRunning the Client
This should be done with this PR only (or cherry-picking the second commit onto
master
).Output
On
master
, this will result inWith this PR, a RST message is replied and no buffer overflow / crash should appear.
Issues/PRs references
None